<template>
  <div class="date">
    <el-row type="flex" justify="end">
      <el-select style="width: 120px" v-model="yearNow" @change="changeDate">
        <el-option
          v-for="item in yearList"
          :label="item"
          :key="item"
          :value="item"
        ></el-option>
      </el-select>
      <el-select
        style="width: 120px; margin-left: 10px"
        v-model="monthNow"
        @change="changeDate"
      >
        <el-option v-for="item in 12" :key="item" :value="item"></el-option>
      </el-select>
    </el-row>
    <el-calendar v-model="dateNow">
      <template slot="dateCell" slot-scope="{ date }">
        <!-- 里面为 {{date,data}}两个数据  -->
        <!-- <div>{{ date }} --- {{ data }}</div> -->
        <div class="date-content">
          <span class="text"> {{ date.getDate() }} </span>
          <span class="rest" v-if="isWeekend(date)"> 休 </span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  name: "calendar",
  data() {
    return {
      dateNow: new Date(),
      yearList: [],
      yearNow: null,
      monthNow: null,
    };
  },
  created() {
    // console.log(this.dateNow);
    let year = this.dateNow.getFullYear();
    this.yearNow = year;

    let month = this.dateNow.getMonth() + 1;
    this.monthNow = month;

    for (let i = year - 5; i < year + 5; i++) {
      this.yearList.push(i);
    }
  },
  methods: {
    changeDate() {
      //   this.yearNow + this.monthNow;
      this.dateNow = new Date(`${this.yearNow}-${this.monthNow}-01`);
    },

    isWeekend(date) {
      return date.getDay() == 0 || date.getDay() == 6;
    },
  },
};
</script>

<style  scoped>
::v-deep .el-calendar-day {
  height: auto;
}
::v-deep .el-calendar-table__row td,
::v-deep .el-calendar-table tr td:first-child,
::v-deep .el-calendar-table__row td.prev {
  border: none;
}
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
::v-deep .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
::v-deep .el-calendar__header {
  display: none;
}
::v-deep .el-input.el-input--suffix input {
  height: 28px;
}
::v-deep .el-input.el-input--suffix .el-select__caret {
  line-height: 28px;
}
</style>